package zgame.main;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import net.sf.ehcache.Element;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import zgame.config.loader.ServerPropertiesReader;
import zgame.config.loader.ServiceConfigReader;
import zgame.utils.CacheUtil;

public class Initialize {
  private static Logger log = Logger.getLogger(Initialize.class);
  
  public static ServiceConfigReader serviceConfigReader = new ServiceConfigReader();
  public static ServerPropertiesReader serverPropertiesReader = new ServerPropertiesReader();

  public static void init() throws IOException {
    // Init log4J
    Properties logProperties = new Properties();
    logProperties.load(new FileInputStream("conf/log4j.properties"));
    PropertyConfigurator.configure(logProperties);
    log.info("Init log4j done");
    
    serverPropertiesReader.loadConfig();
    serviceConfigReader.loadConfig();
    log.info("Load config done!");
  }
  
  public static void initForCache() {
    Element element = new Element("initCacheTime", String.valueOf(System.currentTimeMillis()));
    CacheUtil.cacheLv1.put(element);
    CacheUtil.cacheLv2.put(element);
    CacheUtil.cacheLv3.put(element);
  }
}
